package org.domon.manager.util;

import java.util.List;

import org.domon.manager.sys.model.Menu;

public class HtmlUtil {

	public static StringBuffer generateTreeHtml(List<Menu> menuList) {
		if (menuList == null || menuList.isEmpty()) {
			return new StringBuffer();
		}

		StringBuffer htmlBuffer = new StringBuffer();
		htmlBuffer.append("<ul class=\"easyui-tree\" data-options=\"state:'closed',animate:true,lines:true\">");
		for (Menu menu : menuList) {
			htmlBuffer.append("<li data-options=\"id:'menu").append(menu.getMenuId()).append("',iconCls:'").append(menu.getIcon()).append("',attributes:{url:'")
					.append(menu.getUrl()).append("'}\">");
			htmlBuffer.append("<span>").append(menu.getMenuName()).append("</span>");
			htmlBuffer.append(generateTreeHtml(menu.getSubmenuList()));
			htmlBuffer.append("</li>");
		}
		htmlBuffer.append("</ul>");
		return htmlBuffer;
	}
}
